package exercise.testForPrint;

import java.io.InputStream;
import java.util.Scanner;


/*
* Classname:Main
*
* Version:0.1
*
* Date:2016/9/21
*
* Copyright WeiZeHao iss2015302580332
*/

public class Main
{

    public static void main(String[] args)
    {
        Main.testPrint();           //测试各种Print函数
        Main.testScanner();         //测试Scanner
        Main.testInput();           //测试InputStream
        TestGui.testDialog_1();     //测试对话框
        TestGui.testDialog_2();     //测试对话框和输入框
        TestGui.addition();         //3.8课后练习题
    }// end method main

    /*To test methods in PrintStream*/
    public  static  void testPrint()
    {
        /*定义一些供测试的临时变量*/
        boolean bool = true;
        int i = 12;
        int j = 7;
        int m = 123456;
        float f = 2.56f;
        double pi = 3.1415926;
        double d = 256.153212;
        char c = 'a';
        String s = "Welcome to Java!";

        /*print输出*/
        System.out.print(c);
        System.out.print(s);
        System.out.print(i);
        System.out.print(f);

        /*println输出*/
        System.out.println(bool);
        System.out.println(c);
        System.out.println(pi);
        System.out.println(j);
        System.out.println(s);

        /*printf输出*/
        System.out.printf("%6d",i);
        System.out.println();
        System.out.printf("%08d",j);
        System.out.println();
        System.out.printf("%x",m);
        System.out.println();
        System.out.printf("%9.3f",pi);
        System.out.println();
        System.out.printf("%-9.3f",pi);
        System.out.println();
        System.out.printf("%-9.4e",d);

    }//  end method testPrint

    /*test methods in Scanner*/
    public static void testScanner()
    {
        /*定义供测试的临时变量*/
        String s1 = "Hello my lady\nWelcome to Java";
        String s2 = "3.1415926 1.23e+05";
        String s3 = "11 23 35";
        Scanner scan1 = new Scanner(s1);
        Scanner scan2 = new Scanner(s1);
        Scanner scan3 = new Scanner(s2);
        Scanner scan4 = new Scanner(s3);
        Scanner scan5 = new Scanner(s2);
        Scanner scan6 = new Scanner(s3);

        /*逐个词输出*/
        while(scan1.hasNext())
        {
            System.out.println(scan1.next());
        }
        scan1.close();

        /*逐行输出*/
        while(scan2.hasNextLine())
        {
            System.out.println(scan2.nextLine());
        }
        scan2.close();

        /*读取普通写法和科学计数法输入的浮点数并输出*/
        while(scan3.hasNextDouble())
        {
            System.out.println(scan3.nextDouble());
        }
        scan3.close();

        /*读取普通整数字符串并输出*/
        while(scan4.hasNextInt())
        {
            System.out.println(scan4.nextInt());
        }
        scan4.close();

        /*
        * 用nextInt()读取浮点数字符串
        * 失败，不能用nextInt()读取浮点数字符串
        */
//        while(scan5.hasNext())
//        {
//            System.out.println(scan5.nextInt());
//        }

        /*用nextDouble()读取整数字符串并输出*/
        while(scan6.hasNext())
        {
            System.out.println(scan6.nextDouble());
        }
        scan6.close();

    }// end method testScanner

    /*test methods in InputStream*/
    public static  void  testInput()
    {
        System.out.println("1.输入整数 2.输入浮点数 3.输入字符串 请选择");
        InputStream input = System.in;
        Scanner scan1 = new Scanner(input);
        int choice = scan1.nextInt();           //记录用户选择

//        try {
//            input.close();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
        /*内层System.in关闭后，外层Scanner不能正常工作*/

        switch (choice)
        {
            case 1:
                System.out.println("请输入一个整数：");
                System.out.printf("您输入的整数为%d", scan1.nextInt());
                break;
            case 2:
                System.out.println("请输入一个浮点数：");
                System.out.printf("您输入的浮点数为%f", scan1.nextDouble());
                break;
            case 3:
                System.out.println("请您输入一个字符串：");
                System.out.printf("您输入的字符串为：", scan1.next());
                break;
            default:
                break;
        }

    }// end method testInput
}//end class Main
